<%
require "src/pacote"
require "src/prioridade"
require "src/timestamp"

def show_pacotes pacotes
%>
  <div class="post">
    <h1 class="title">Lista de Pacotes</h1>
    <div class="entry">
      <div id="demo"><br/>
        <table id="example" border="0" cellpadding="0" class="display" align="center">
          <thead>
            <tr>
              <th width="5%">#</th>
              <th width="3%">&nbsp;</th>
              <th>Nome</th>
              <th width="15%">Inicio</th>
              <th width="15%">Fim</th>
              <th width="10%">Completado</th>
              <th width="6%">Status</th>
            </tr>
          </thead>
          <tbody> <%
            pacotes.each do |pacote| %>
              <tr>
                <td><%= pacote.id_pacote %></td>
                <td> <%
                  case pacote.prioridade
                  when Prioridade::NORMAL
                  %><img src="images/3-normal.png" alt="3 - Normal" title="3 - Normal" /><%
                  when Prioridade::BAIXA
                  %><img src="images/2-baixa.png" alt="2 - Baixa" title="2 - Baixa" /><%
                  when Prioridade::NENHUMA
                  %><img src="images/1-nenhum.png" alt="1 - Nenhuma" title="1 - Nenhuma" /><%
                  when Prioridade::ALTA
                  %><img src="images/4-alta.png" alt="4 - Alta" title="4 - Alta" /><%
                  when Prioridade::MUITO_ALTA
                  %><img src="images/5-muito.alta.png" alt="5 - M. Alta" title="5 - M. Alta" /><%
                  end
                  url = "lista_links.rhtml?id_pacote=#{pacote.id_pacote}" %>
                </td>
                <td>
                  <a href=<%= url %>>
                    <img src="images/folder.png" alt="Folder"/>
                    &nbsp;&nbsp;<%= pacote.nome %>&nbsp;(<%= sprintf("%.2f MB", pacote.tamanho.to_i/1024.0) %>)
                  </a>
                </td> <%
                begin
                  data_inicio_to_s = StrTime.timestamp(pacote.data_inicio.to_time)
                rescue Exception
                  begin
                    data_inicio_to_s = StrTime.timestamp(pacote.data_inicio)
                  rescue Exception
                    data_inicio_to_s = "<img src=\"images\/hourglass.png\" alt=\"Progress\" \/>"
                  end
                end %>
                <td align="center"><%= data_inicio_to_s %> </td> <%
                if pacote.data_fim == nil %>
                  <td align="center"><img src="images/hourglass.png" alt="Progress" /></td> <%
                else
                  if pacote.data_fim.class.to_s == "DBI::Timestamp"
                    data_fim_to_s = StrTime.timestamp(pacote.data_fim.to_time)
                  else
                    data_fim_to_s = StrTime.timestamp(pacote.data_fim)
                  end %>
                  <td align="center"><%= data_fim_to_s %> </td> <%
                end
                # completado
                unless pacote.completado %>
                  <td align="center"><img src="images/cancel.png" alt="Não" /></td> <%
                else %>
                  <td align="center"><img src="images/accept.png" alt="Não" /></td> <%
                end
                # status
                unless pacote.problema %>
                  <td align="center"><img src="images/accept.png" alt="Não" /></td> <%
                else %>
                  <td align="center"><img src="images/exclamation.png" alt="Não" /></td> <%
                end
                print "\n" %>
              </tr> <%
            end # => pacotes.each %>
          </tbody>
          <tfoot>
            <tr>
              <th colspan="7" align="center">RS-Online ~ version 1.0b ~ Powered by eRuby</th>
            </tr>
          </tfoot>
        </table>
      </div>
    </div>
    <div class="meta">
      <p class="links"></p>
    </div>
  </div> <%
end
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name       : Professional
Description: A two-column, fixed-width design with dark color scheme background.
Version    : 1.0
Released   : 20081230

-->

<html>
  <head>
    <link rel="icon" href="images/favicon.png" type="image/x-icon" />
    <link rel="shortcut icon" href="images/favicon.png" type="image/x-icon" />
    <!-- PAGINAÇÃO VIA AJAX -->
    <style type="text/css" title="currentStyle">
      @import "pagination/css/demo_page.css";
      @import "pagination/css/demo_table.css";
    </style>
    <script type="text/javascript" language="javascript" src="pagination/js/jquery.js"></script>
    <script type="text/javascript" language="javascript" src="pagination/js/jquery.dataTables.js"></script>
    <script type="text/javascript" charset="utf-8">
      $(document).ready(function() {
        $('#example').dataTable( {
          "sPaginationType": "full_numbers"
        } );
      } );
    </script>
    <!-- PAGINAÇÃO VIA AJAX -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>RS-Online ~ version 1.0b ~ Powered by eRuby</title>
    <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
  </head>
  <body>

    <div id="wrapper">

      <div id="header">
        <div id="logo">
          <h1><a href="#">RS-Online Beta</a></h1>
          <p>version 1.0b ~ Powered by eRuby</p>
        </div>
        <!-- end #logo -->
        <div id="menu">
          <ul>
            <li class="active"><a href="index.rhtml">Home</a></li>
            <li><a href="#">About Us</a></li>
            <li><a href="#">Products</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Contact Us</a></li>
          </ul>
        </div>
        <!-- end #menu -->
      </div>
      <!-- end #header -->
      <div id="page">
        <!--<div id="header-pic"></div>-->
        <div id="content">
          <%
          pacotes = Pacote.select_lista false
          if pacotes == nil %>
            <div class="post">
              <h1 class="title">Ocorreu um erro!</h1>
              <div class="entry">
                <p>
                  Houve algum erro com a listagem dos pacotes.<br/>
                  Contate o administrador!
                </p>
              </div>
            </div> <%
          else
            begin
              show_pacotes pacotes
            rescue Exception %>
              <h1 class="title">Ocorreu um erro!</h1>
              <p>Não foi possível carregar a página. Contate o administrador!</p> <%
            end # => begin - rescue
          end %>
        </div>
        <!-- end #content -->
        <div id="sidebar">
          <div id="sidebar-bgtop"></div>
          <div id="sidebar-content">
            <div id="sidebar-bgbtm">
              <ul>
                <li id="search">
                  <h2>Search</h2>
                  <form method="get" action="">
                    <fieldset>
                      <input type="text" id="s" name="s" value="" />
                      <input type="submit" id="x" value="Search" />
                    </fieldset>
                  </form>
                </li>
                <li>
                  <h2>Pacotes</h2>
                  <ul>
                    <li><a href="add_pacote.rhtml"><img alt="new" src="images/package_add.png"/>&nbsp;Novo Pacote</a></li>
                    <li><a href="lista_pacotes.rhtml"><img alt="lst" src="images/drive_web.png"/>&nbsp;Lista de Pacotes</a></li>
                    <li><a href="lista_pacotes_ocultos.rhtml"><img alt="oct" src="images/safe.png"/>&nbsp;Lista de Pacotes Ocultos</a></li>
                  </ul>
                </li>
                <li>
                  <h2>Downloads</h2>
                  <ul>
                    <li><a href="#"><img alt="est" src="images/chart_bar.png"/>&nbsp;Estatística (em construção)</a></li>
                    <li><a href="log_downloads.rhtml"><img alt="log" src="images/report.png"/>&nbsp;Log de Downloads</a></li>
                  </ul>
                </li>
              </ul>
            </div>
          </div>
        </div>
        <!-- end #sidebar -->
        <div style="clear:both; margin:0;"></div>
      </div>
      <!-- end #page -->

    </div>

    <div id="footer">
      <p>&copy; 2010. All Rights Reserved. Design by Nightcrawler. RS-Online is powered by eRuby.</p>
    </div>
    <!-- end #footer -->
  </body>
</html>